$(function () {
    $('[data-role="do_convert"]').click(function () {
        var first = $('#default_table').find('li').eq(0).attr('id');
        do_convert(first);
    })
    bind_convert();
})

var do_convert = function (table, single) {
    if(table){
        var $li = $('#' + table);
        $li.find('span').html('正在转移。。。。。。。')
        $li.attr('class', 'show_info');
        $.get(U('Convert/'+CONTROLLER_NAME+'/doConvert'), {table: table}, function (result) {
            $li.find('span').html(result.info)
            if (result.status == 1 || result.status == 2) {
                $li.attr('class', 'show_success_' + result.status);
            } else {
                $li.attr('class', 'show_error');
                $li.next().html('<a class="btn-xs btn-primary" data-role="convert"  data-table="' + table + '" data-single="1">点击单个转移</a> <a class="btn-xs btn-primary" data-role="convert"  data-table="' + table + '" data-single="0">点击转移以下全部</a>');
                bind_convert();
            }
            if (single != 1) {
                do_convert(result.next);
            }
        })
    }

}


var bind_convert = function () {
    $('[data-role="convert"]').unbind('click');
    $('[data-role="convert"]').click(function () {
        var $this = $(this);
        do_convert($this.attr('data-table'), $this.attr('data-single'));
    })
}

